﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Frame;
using System.Windows.Forms;
using System.Drawing;
using System.Xml;

namespace AdtMotion
{
    public class Global
    {
        private bool m_IsShow;
        private string m_AppRootPath; // 应用程序所在目录
        private FrameApplication app;
        private Icon icon;//窗体图标
        private string menuFileDir;//菜单参数文件所在位置
        private string m_IniParam = System.Windows.Forms.Application.StartupPath + @"\PARAM\MainParam.ini";
        public Global()
        {
            m_IsShow = true;
            m_AppRootPath = Directory.GetCurrentDirectory();
            icon = new Icon(m_AppRootPath + "\\logo.ico");
            menuFileDir = m_AppRootPath + "\\Menu\\Menu.xml";
            GetMenuList();
        }

        public string MainParam
        {
            get { return m_IniParam; }
        }

        public FrameApplication App
        {
            set { app = value; }
            get { return app; }
        }

        public Icon ICON
        {
            get { return icon; }
        }

        public bool IsShow
        {
            set { m_IsShow = value; }
            get { return m_IsShow; }
        }


        /// <summary>
        /// 获取菜单列表
        /// </summary>
        private void GetMenuList()
        {
            Frame.Menu.MenuList = new List<Frame.Menu.tMenu>();
            Frame.Menu.StatMenuList = new Dictionary<string, Frame.Menu.tMenu>();
            if (Directory.Exists(menuFileDir))
                return;
            XmlDocument doc = new XmlDocument();
            doc.Load(menuFileDir);
            XmlNode rootNode = doc.SelectSingleNode("AdtMotion");
            XmlNode menuNode = rootNode.SelectSingleNode("menu");
            XmlNodeList menuNodes = menuNode.ChildNodes;
            foreach (XmlNode node in menuNodes)
            {
                Frame.Menu.tMenu menu = new Frame.Menu.tMenu();
                menu.name = node.Name;
                menu.image = Image.FromFile(m_AppRootPath + "\\Menu\\" + node.Attributes["image"].Value.ToString());
                menu.txt = node.InnerText;
                Frame.Menu.MenuList.Add(menu);
            }
            XmlNode smenuNode = rootNode.SelectSingleNode("staticMenu");
            foreach (XmlNode node in smenuNode)
            {
                Frame.Menu.tMenu menu = new Frame.Menu.tMenu();
                menu.name = node.Name;
                menu.image = Image.FromFile(m_AppRootPath + "\\Menu\\" + node.Attributes["image"].Value);
                menu.txt = node.InnerText;
                Frame.Menu.StatMenuList.Add(node.Name, menu);
            }
        }
    }
}
